import { BaseEntity } from '@cool-midway/core';
import { Column, Entity, Index } from 'typeorm';
import { GoodsSpecEntity } from './spec';

/**
 * 商品信息 - 包含本地业务字段和 Oracle 同步字段
 */
@Entity('goods_info')
export class GoodsInfoEntity extends BaseEntity {
  @Index()
  @Column({ comment: '类型ID' })
  typeId: number;

  @Index()
  @Column({ comment: '标题' })
  title: string;

  @Column({ comment: '副标题', nullable: true })
  subTitle: string;

  @Column({ comment: '主图', nullable: true })
  mainPic: string;

  @Column({ comment: '图片', type: 'json', nullable: true })
  pics: string[];

  @Column({
    comment: '价格',
    type: 'decimal',
    precision: 12,
    scale: 4,
    default: 0,
  })
  price: number;

  @Column({ comment: '已售', default: 0 })
  sold: number;

  @Column({ comment: '详情', type: 'text', nullable: true })
  content: string;

  @Index()
  @Column({ comment: '状态 0-下架 1-上架', default: 0 })
  status: number;

  @Column({ comment: '排序', default: 0, nullable: true })
  sortNum: number;

  @Column({ comment: '属性(多选,逗号分隔)', default: '', length: 50 })
  attribute: string;

  @Index({ unique: true })
  @Column({ comment: '商品ID (Oracle)', length: 50, nullable: true })
  goodsId: string;

  @Column({ comment: '企业ID (Oracle)', length: 50, nullable: true })
  entId: string;

  @Index()
  @Column({ comment: '商品编码 (Oracle)', length: 100, nullable: true })
  goodsCode: string;

  @Column({ comment: '商品名称 (Oracle)', length: 255, nullable: true })
  oracleGoodsName: string;

  @Column({ comment: '商品规格 (Oracle)', length: 255, nullable: true })
  goodsSpec: string;

  @Column({ comment: '生产厂家 (Oracle)', length: 255, nullable: true })
  manufacturer: string;

  @Column({ comment: '单位 (Oracle)', length: 50, nullable: true })
  unit: string;

  @Column({ comment: '批准文号 (Oracle)', length: 100, nullable: true })
  approvalNo: string;

  @Column({ comment: '剂型 (Oracle)', length: 100, nullable: true })
  formula: string;

  @Column({ type: 'int', comment: '中包装 (Oracle)', nullable: true })
  midpack: number;

  @Column({ type: 'decimal', precision: 10, scale: 2, comment: '数量? (Oracle)', nullable: true })
  qty: number;

  @Column({ comment: '计划类别 (Oracle)', length: 100, nullable: true })
  planCate: string;

  @Column({ comment: '助记码 (Oracle)', length: 100, nullable: true })
  logogram: string;

  @Column({ type: 'int', comment: '整件限制数量 (Oracle)', nullable: true })
  wholLimtNum: number;

  @Column({ type: 'int', comment: '库存数量 (Oracle)', nullable: true, default: 0 })
  storNum: number;

  @Column({ type: 'tinyint', comment: '是否允许拆零销售(0=是, 1=否) (Oracle)', nullable: true, default: 1 })
  isMidpackSaleDisabled: number;

  @Column({ comment: '商品分类(G) (Oracle)', length: 50, nullable: true })
  gCategory: string;

  @Column({ comment: '质量分类(Q) (Oracle)', length: 100, nullable: true })
  qCategory: string;

  @Column({ type: 'tinyint', comment: '是否隐藏(0=否, 1=是) (Oracle)', nullable: true, default: 0 })
  oracleIsHidden: number;

  @Column({ type: 'tinyint', comment: '是否处方药 (Oracle)', nullable: true })
  isPres: number;

  @Column({
    comment: '级别1含税销售价 (Oracle)',
    type: 'decimal',
    precision: 12,
    scale: 6,
    nullable: true,
  })
  saleTaxPriceL1: number;

  @Column({
    comment: '级别1不含税销售价 (Oracle)',
    type: 'decimal',
    precision: 12,
    scale: 6,
    nullable: true,
  })
  salePriceL1: number;

  @Column({
    comment: '级别2含税销售价 (Oracle)',
    type: 'decimal',
    precision: 12,
    scale: 6,
    nullable: true,
  })
  saleTaxPriceL2: number;

  @Column({
    comment: '级别2不含税销售价 (Oracle)',
    type: 'decimal',
    precision: 12,
    scale: 6,
    nullable: true,
  })
  salePriceL2: number;

  @Column({
    comment: '级别3含税销售价 (Oracle)',
    type: 'decimal',
    precision: 12,
    scale: 6,
    nullable: true,
  })
  saleTaxPriceL3: number;

  @Column({
    comment: '级别3不含税销售价 (Oracle)',
    type: 'decimal',
    precision: 12,
    scale: 6,
    nullable: true,
  })
  salePriceL3: number;

  @Column({
    comment: '级别4含税销售价 (Oracle)',
    type: 'decimal',
    precision: 12,
    scale: 6,
    nullable: true,
  })
  saleTaxPriceL4: number;

  @Column({
    comment: '级别4不含税销售价 (Oracle)',
    type: 'decimal',
    precision: 12,
    scale: 6,
    nullable: true,
  })
  salePriceL4: number;

  @Column({ comment: '品牌编码 (Oracle)', length: 50, nullable: true })
  brandCode: string;

  @Column({ comment: '近效期价格 (Oracle)', type: 'decimal', precision: 12, scale: 6, nullable: true })
  nextValPrice: number;

  @Column({ type: 'datetime', comment: '近效期日期 (最早批次有效期)', nullable: true })
  nearestExpiredDate: Date;

  specs: GoodsSpecEntity[];
}
